﻿

var queryPbTemplateUrl = ArrangeUrl + "/HsTemplate/queryList";

//当前选择模板
var _nowselect_template = "";


$(function () {

    loadTemplateTableData();
    loadPbTemplateResolution("select_relepb");

    //取消选择模板
    $("#but_cancel").click(function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    });

    //确定选择模板
    $("#but_ok").click(function () {
        chooseTemplate();
    });
})


//选择模板
function chooseTemplate() {

    var _templateId = $($(_nowselect_template).children("td").get(0)).html();
    var _templayeName = $($(_nowselect_template).children("td").get(2)).html();
    var _resolution = $($(_nowselect_template).children("td").get(3)).html();
    var _url = $($(_nowselect_template).children("td").get(5)).html();

    if (_templateId != "" && _templateId != undefined) {
        var index = parent.layer.getFrameIndex(window.name);
        //console.log(_templateId);
        //执行父页面加载模板方法
        parent.initLoadTemplatePage(_templateId + "\2" + _templayeName + "\2" + _resolution + "\2" + _url);
        parent.layer.close(index);

    } else {
        alert("请选择一个模板");
    }
}

function queryTemplate() {
    loadTemplateTableData();
}

//初始化表格数据
function loadTemplateTableData() {
    var _html = "";

    $.ajax({
        url: queryPbTemplateUrl,
        type: 'get',
        data: {
            templateName: $("#text_search").val(),
            resolution: $("#select_relepb").val()
        },
        success: function (d) {
            if (JSON.parse(d).status == "0") {
                var _templateJson = JSON.parse(d).data;
                for (var i = 0; i < _templateJson.list.length; i++) {
                    var _tId = _templateJson.list[i].templateId;
                    var _tName = _templateJson.list[i].templateName;
                    var _tType = _templateJson.list[i].templateType;
                    var _resolution = _templateJson.list[i].resolution;
                    var _editTime = _templateJson.list[i].editTime;
                    var _url = _templateJson.list[i].templateURL;

                    _html += "<tr ondblclick='chooseTemplate()' onclick='change_selectstyle(this);'>" +
                                 "<td style='display:none'>" + _tId + "</td>" +
                                 "<td>" + (i + 1) + "</td>" +
                                 "<td>" + _tName + "</td>" +
                                 "<td>" + _resolution + "</td>" +
                                 "<td>" + _editTime + "</td>" +
                                 "<td style='display:none'>" + _url + "</td>" +
                            +"</tr>";
                }
                $("#template_table").html(_html);
            }
        }
    });
}



//切换选中样式
function change_selectstyle(t) {

    _nowselect_template = t;
    //消除样式
    $("#t_table tr").children().each(function () {
        $(this).css({
            "background": "white",
            "color": "black"
        });
    });

    $(t).children().css({
        "background": "#1AACFF",
        "color": "white"
    });
}
